import BPerson from "@/components/b-person.vue";
import { useAddTools } from "@/utils/useAddTools";
import { CSS2DObject } from "three/examples/jsm/Addons.js";
import { createVNode, render } from "vue";

const { hasGroup } = useAddTools()
window.jzPoints = {}
export default function () {
  const group = hasGroup('设备', false)
  if (group) {
    group.children.forEach((item) => {
      const jzList = item.userData.detailDtos.find(node => node.deviceType === '001')
      if (jzList) {
        jzList.deviceIdList.forEach((node) => {
          window.jzPoints[node] = item.position
          const label = createdPersonCSS2DObject({
            name: item.name,
            jzNo: node
          })
          label.name = node.name
          item.add(label)
        })
      }
    })
  }
}

function createdPersonCSS2DObject (item) {
  const container = document.createElement('div')
  const vm = createVNode(BPerson, {
    info: item,
  }, null)
  render(vm, container)
  const label = new CSS2DObject(container.firstElementChild as Node)
  label.Vnode = vm
  return label
}